<?php

/**
 * Description of Search
 *
 * @author Alisson Chiquitto<chiquitto@chiquitto.com.br>
 */
class ZFDulcet_Grid_Deploy_Table_Search extends ZFDulcet_Form
{

    protected $group = array();

    public function __construct($options = null)
    {
        parent::__construct('Search', $options);
        $this->addClass('datatableSearch');
        $this->setMethod(Zend_Form::METHOD_GET);
        
        if((isset($options['advanced'])) and ($options['advanced'] === TRUE)){
            $this->_enableAdvanced();
        }

        if((isset($options['allresults'])) and ($options['allresults'] === TRUE)){
            $this->_enableAllResults();
        }
                
        $this->_configGroupIn();
    }

    protected function _configGroupIn($doGroupIn = true)
    {
        $this->addElement($stBannerElement = new ZFDulcet_Form_Element_Text('q', array(
            'label' => 'Pesquisar',
        )));
        $stBannerElement
                ->removeDecorator('HtmlTag')
                ->removeDecorator('htmltag1')
        ;
        $this->group[] = 'q';

        $this->addElement($btOkElement = new ZFDulcet_Form_Element_Button('searchbt', array(
            'label' => 'ok',
            'disableLoadDefaultDecorators' => true,
            'type' => 'submit',
        )));
        ZFKiller_Form_Element::addAttrib($btOkElement, 'class', 'green');
        $btOkElement
                ->addDecorator('ViewHelper')
        ;
        $this->group[] = 'searchbt';

        if ($doGroupIn === true) {
            $this->addDisplayGroupIn($this->group);
        }
    }
    
    private function _enableAdvanced(){
        $this->addElement($btAdvanced = new ZFDulcet_Form_Element_Button('btAdvanced', array(
            'label' => 'Avançada',
            'disableLoadDefaultDecorators' => true,
        )));
        
        ZFKiller_Form_Element::addAttrib($btAdvanced, 'class', 'smaller');

        $btAdvanced->addDecorator('ViewHelper');
        
        $this->group[] = 'btAdvanced';
    }

    private function _enableAllResults(){
        $this->addElement($btAllResults = new ZFDulcet_Form_Element_Button('btAllResults', array(
            'label' => 'Todos',
            'disableLoadDefaultDecorators' => true,
            'type' => 'submit',
        )));
        
        ZFKiller_Form_Element::addAttrib($btAllResults, 'class', 'smaller');

        $btAllResults->addDecorator('ViewHelper');
        
        $this->group[] = 'btAllResults';
    }

}